<%--
  Created by IntelliJ IDEA.
  User: Lenovo
  Date: 2024/9/20
  Time: 下午9:54
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <meta charset="utf-8">
    <title>添加用户</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="../../css/public.css" media="all">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>
<div class="layui-form layuimini-form">
    <!-- 用户ID -->
    <div class="layui-form-item">
        <label class="layui-form-label required" >用户ID</label>
        <div class="layui-input-block">
            <input type="text" id="id" name="id" lay-verify="required"  lay-reqtext="ID不能为空" placeholder="请输入学号/工号" value="" class="layui-input" >
        </div>
    </div>
    <!-- 用户姓名 -->
    <div class="layui-form-item">
        <label class="layui-form-label required">用户姓名</label>
        <div class="layui-input-block">
            <input type="text" name="name" lay-verify="required" lay-reqtext="用户姓名不能为空" placeholder="请输入用户姓名" value="" class="layui-input">
        </div>
    </div>

    <!-- 性别 -->
    <div class="layui-form-item">
        <label class="layui-form-label">性别</label>
        <div class="layui-input-block">
            <select name="gender" >
                <option value="">--请选择--</option>
                <option value="男">男</option>
                <option value="女">女</option>
            </select>
        </div>
    </div>

    <!-- 身份 -->
    <div class="layui-form-item">
        <label class="layui-form-label required">身份</label>
        <div class="layui-input-block">
            <select name="identity" lay-verify="required" lay-reqtext="请选择身份">
                <option value="">--请选择--</option>
                <option value="1">管理员</option>
                <option value="2">教师</option>
                <option value="3">学生</option>
            </select>
        </div>
    </div>

    <!-- 所属学院 -->
    <div class="layui-form-item">
        <label class="layui-form-label required">所属学院</label>
        <div class="layui-input-block">
            <select name="college_id" lay-verify="required" lay-reqtext="请选择所属学院">
                <option value="">--请选择--</option>
                <option value="1">机电工程学院</option>
                <option value="2">机械工程学院</option>
                <option value="3">材料科学与工程学院</option>
                <option value="4">化学工程与技术学院</option>
                <option value="5">信息与通信工程学院</option>
                <option value="6">仪器与电子学院</option>
                <option value="7">大数据学院</option>
                <option value="8">理学院</option>
                <option value="9">经济与管理学院</option>
                <option value="10">人文社会科学学院</option>
                <option value="11">体育学院</option>
                <option value="12">艺术学院</option>
                <option value="13">软件学院</option>
                <option value="14">环境与安全工程学院</option>
                <option value="15">电气与控制工程学院</option>
                <option value="16">能源动力工程学院</option>
            </select>
        </div>
    </div>

    <!-- 手机号码 -->
    <div class="layui-form-item">
        <label class="layui-form-label">手机号码</label>
        <div class="layui-input-block">
            <input type="text" name="phone_number" placeholder="请输入手机号码" class="layui-input">
        </div>
    </div>

    <!-- 密码 -->
    <div class="layui-form-item">
        <label class="layui-form-label required">密码</label>
        <div class="layui-input-block">
            <input type="password" name="password" lay-verify="required" lay-reqtext="密码不能为空" placeholder="请输入密码" class="layui-input">
        </div>
    </div>

    <!-- 提交按钮 -->
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">添加</button>
        </div>
    </div>
</div>

<script src="../../lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script>
    layui.use(['form'], function () {
        var form = layui.form,
            layer = layui.layer,
            $ = layui.$;

        //监听提交
        form.on('submit(saveBtn)', function (data) {
            var data = JSON.stringify(data.field);
            //alert(data)
            $.post('${pageContext.request.contextPath}/userServlet?method=addUser', {"data": data}, function (response) {
                if (response == 1) {
                    layer.msg('添加成功', {icon: 1}, function () {
                        window.location = 'addUser.jsp'; // 跳转回当前页面，刷新表单
                    });
                } else {
                    layer.msg('添加失败', {icon: 2});
                }
            }, "json");

            return false;
        });

    });
</script>
</body>
</html>
